package com.ytd.smartcanteen.weighting.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.ytd.common.util.LogUtil;
import com.ytd.smartcanteen.weighting.MainActivity;

import java.util.Objects;

public class ReplacedBroadcast extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Objects.equals(intent.getAction(), Intent.ACTION_MY_PACKAGE_REPLACED)) {
            try {
                Intent intent2 = new Intent(context, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent2);
            } catch (Throwable e) {
                LogUtil.e("ReplacedBroadcast error：" + e.getMessage());
                try {
                    Intent intent2 = new Intent(context, MainActivity.class);
                    context.startActivity(intent2);
                } catch (Throwable ex) {
                    LogUtil.e("ReplacedBroadcast error2：" + e.getMessage());
                }
            }
        }
    }
}